package org.example.myleet.p965;

import org.example.myleet.Utils.TreeNode;

public class Solution {
    public boolean isUnivalTree(TreeNode root) {
        if (null != root) {
            if (null != root.left) {
                if (root.left.val != root.val) {
                    return false;
                }
                if (!isUnivalTree(root.left)) {
                    return false;
                }
            }
            if (null != root.right) {
                if (root.right.val != root.val) {
                    return false;
                }
                if (!isUnivalTree(root.right)) {
                    return false;
                }
            }
        }
        return true;
    }
}
